﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using Commandparser;
using FastColoredTextBoxNS;

namespace test
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            Parser p = new Parser();

            p.Parse(fastColoredTextBox1.Text);

            MessageBox.Show(p.Commands[0].Propertys["int"].ToString());
        }

        private void Form1_Load(object sender, EventArgs e)
        {

            AutocompleteMenu menu = new AutocompleteMenu(fastColoredTextBox1);
            List<AutocompleteItem> items = new List<AutocompleteItem>();

            items.Add(new AutocompleteItem("sectionname {\n} ",0,"Section"));

            menu.Items.SetAutocompleteItems(items);

        }

        private TextStyle blackBold = new TextStyle(Brushes.Black, null, FontStyle.Bold);
        private TextStyle comment = new TextStyle(Brushes.LawnGreen, null, FontStyle.Italic);
        private TextStyle statement = new TextStyle(Brushes.Green, null, FontStyle.Italic);

        private void fastColoredTextBox1_TextChanged(object sender, FastColoredTextBoxNS.TextChangedEventArgs e)
        {
            e.ChangedRange.ClearStyle(blackBold,comment,statement);
            e.ChangedRange.ClearFoldingMarkers();

            e.ChangedRange.SetStyle(blackBold, ".+:");
            e.ChangedRange.SetStyle(blackBold, ".+{");
            e.ChangedRange.SetStyle(comment, "\\/\\*.+\\*\\/");
            e.ChangedRange.SetStyle(statement, "@(.+);");

            e.ChangedRange.SetFoldingMarkers("{", "}");
            e.ChangedRange.SetFoldingMarkers("\\/\\*", "\\*\\/");
            e.ChangedRange.SetFoldingMarkers("\\[", "\\]");

        }

        private void fastColoredTextBox1_AutoIndentNeeded(object sender, AutoIndentEventArgs e)
        {
            // if current line is "begin" then next
            // line shift to right
            if (e.LineText.Trim() == "{")
            {
                e.ShiftNextLines = e.TabLength;
                return;
            }
            // if current line is "end" then current
            // and next line shift to left
            if (e.LineText.Trim() == "}")
            {
                e.Shift = -e.TabLength;
                e.ShiftNextLines = -e.TabLength;
                return;
            }
            if (e.LineText.Trim() == "[")
            {
                e.ShiftNextLines = e.TabLength;
                return;
            }
            // if current line is "end" then current
            // and next line shift to left
            if (e.LineText.Trim() == "]")
            {
                e.Shift = -e.TabLength;
                e.ShiftNextLines = -e.TabLength;
                return;
            }
            
        }

    }
}
